/*
 * 1332. Number of 1 Bits
 * Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
 * 
 * 样例
 * For example, the 32-bit integer 11 has binary representation 00000000000000000000000000001011, so the function should return 3.
 * 
 * 2018.06.12 @jeyming
 */
package number_of_1_bits_1332;

public class Number_of_1_bits_1332 {
    /**
     * @param n: an unsigned integer
     * @return: the number of â€™1' bits
     */
    public static int hammingWeight(int n) {
        // write your code here
    	int cnt = 0;
    	while(n > 0) {
    		if(n % 2 == 1) {
    			++cnt;
    		}
    		n /= 2;
    	}
    	return cnt;
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(hammingWeight(00000000000000000000000000001011));
	}

}
